import Vuex from 'vuex'
import defaultState from './state'
import mutations from './mutations'
import getters from './getters'
import actions from './actions'

// vuex的模块导入
import comprehensive from '@/module/comprehensive/store'
// import login from '../module/login/store'
// import meeting from '../module/OA/meeting/store'
// import donate from '../module/OA/donate/store'

export default () => {
  const store = new Vuex.Store({
    // 在严格模式下，无论何时发生了状态变更且不是由 mutation 函数引起的，将会抛出错误
    strict: process.env.NODE_ENV !== 'production',
    state: defaultState,
    mutations,
    getters,
    actions,
    modules: {
      comprehensive
    }
  })

  /**
   * 主要vuex加入热更替的功能
   *
   */
  if (module.hot) {
    module.hot.accept([
      './state',
      './mutations',
      './actions',
      './getters'
    ], () => {
      const newState = require('./state').default
      const newMutations = require('./mutations').default
      const newActions = require('./actions').default
      const newGetters = require('./getters').default

      store.hotUpdate({
        state: newState,
        mutations: newMutations,
        getters: newGetters,
        actions: newActions
      })
    })
  }
  return store
}
